package gqz.mvvm.view;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import gqz.mvvm.R;
import gqz.mvvm.view.custom.MySwitch;

/**
 * Created by Administrator on 2018/3/5.
 */

public class MySwitchActivity extends Activity implements View.OnClickListener {

    private final String TAG = "CustomViewActivity-->";
    private MySwitch s1, s2, s3;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myswitch);


        s1 = (MySwitch) findViewById(R.id.customView_switch1);
        s2 = (MySwitch) findViewById(R.id.customView_switch2);
        s3 = (MySwitch) findViewById(R.id.customView_switch3);
        s3.setPrimaryMode(false);
        s1.setOnCheckedChangeListener(onCheckedChange);
        s2.setOnCheckedChangeListener(onCheckedChange);
        s3.setOnCheckedChangeListener(onCheckedChange);
        Button btn1 = (Button) findViewById(R.id.customView_btn1),
                btn2 = (Button) findViewById(R.id.customView_btn2),
                btn3 = (Button) findViewById(R.id.customView_btn3);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.customView_btn1:
                s3.setChecked(0);
                break;
            case R.id.customView_btn2:
                s3.setChecked(1);
                break;
            case R.id.customView_btn3:
                s3.setChecked(2);
                break;
        }
    }

    MySwitch.OnCheckedChangeListener onCheckedChange = new MySwitch.OnCheckedChangeListener() {
        @Override
        public void onCheckedChange(View view, int status) {
            switch (view.getId()) {
                case R.id.customView_switch1:
                    Log.i(TAG, "Switch1");
                    break;
                case R.id.customView_switch2:
                    Log.i(TAG, "Switch2");
                    break;
                case R.id.customView_switch3:
                    Log.i(TAG, "Switch3");
                    break;
            }
            switch (status) {
                case 0:
                    Log.i(TAG, "左");
                    break;
                case 1:
                    Log.i(TAG, "中");
                    break;
                case 2:
                    Log.i(TAG, "右");
                    break;
            }
        }
    };
}
